<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    searchPlaceholder="请输入单据编号"
    :getList="getList"
    @getDetail="getDetail"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">单据编号</view>
          <view class="rl">{{ item.purchaseBill }}</view>
        </view>
        <view class="option">
          <view class="lf">采购类型</view>
          <view class="rl">{{ item.provisionBroad_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">招标方式</view>
          <view class="rl">{{item.invitationManner_dictText}}</view>
        </view>
        <view class="option">
          <view class="lf">关联项目</view>
          <view class="rl">{{ item.projectId_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">申请人</view>
          <view class="rl">{{ item.proposer_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">费用所属团队</view>
          <view class="rl">{{ item.teamId_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">期望到货时间</view>
          <view class="rl">{{ item.expectUseTime }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { erpPurchaseApplyInvitationAllList } from '@/api/index.js'
import { erpPurchaseApplyInvitationQueryById } from '@/api/index.js'
import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'
export default {
  name: 'HSelectPurchaseCalibrationInputPopup',
  data() {
    return {
      filterMultiDictText,
      initDictOptions,
      dictOptions: {},

      getList: erpPurchaseApplyInvitationAllList,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    showName: {
      type: [String, Number],
      default: null,
    },
    teamId: {
      type: [String, Number],
      default: null,
    },
    demandCompanName: {
      type: [String, Number],
      default: null,
    },
    sysOrgCode: {
      type: [String, Number],
      default: null,
    },
    projectId: {
      type: [String, Number],
      default: null,
    },
    muitFlag: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
    queryParams() {
      const params = {
        ...this.params,
      }
      if (this.teamId) {
        params.teamId = this.teamId
      }
      if (this.keywords) {
        params.purchaseBill = '*' + this.keywords + '*'
      } else {
        params.purchaseBill = ''
      }
      params.checkStatus = 2
      return params
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
      erpPurchaseApplyInvitationQueryById({ id: value }).then((res) => {
        if (res.success) {
          this.$refs.hSelectInputPopup.title = res.result.purchaseBill
          this.$emit('select', {
            data: res.result,
            id: value,
          })
        }
      })
    }
  },
}
</script>

<style lang="scss" scoped>

// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
